<?php
function req_form($value) {
	$value = mysql_real_escape_string(str_replace('	','',$value));
	return $value;
}
function max_caps($value) {
	$value = strtoupper($value);
	/*$value = htmlentities($value);*/
	// INACTIVO POR COMP/ COM UTF-8
	$value = preg_replace("/(&)([a-z])([a-z]+;)/i", '$2', $value);
	/*$value = preg_replace("/[^A-Z0-9]/i", ' ', $value);*/
	$value = preg_replace("/\s+/i", ' ', $value);
	$value = trim($value);
	return $value;
}
function trimall($str, $charlist = "\n\r\0\x0B")
{
  return str_replace(str_split($charlist),'',$str);
}
function form_pr($form,$target,$action,$method) {
	echo '<form accept-charset="utf-8" id="'.$form.'" name="'.$form.'" action="'.$action.'" method="'.$method.'" runat="server">';
}
 function pesq_rapida() {
 echo '<table width="100%" border="0" cellpadding="5" cellspacing="0">
      <form action="'.$_SERVER['PHP_SELF'].'?ACMN=prc" method="post">
        <tr bgcolor="#ACB1CC">
          <td>Pesquisa
          <input name="palavras" type="text" size="50"></td>
          <td><input type="submit" name="Submit" value="Pesquisar"></td>
        </tr>
      </form>
</table>';
 }
function rt_field($type,$MODE,$name,$value,$max,$size,$CSSBold,$CSS) {
  $prtSTR = '';
 // INPUT
 	$fieldTypes = array('hidden','text','password','button','submit','file','radio');
  if (in_array($type, $fieldTypes)) {
	if ($MODE == 'ED') {
	$prtSTR .=  '<input type="'.$type.'" name="'.$name.'" id="'.$name.'" value="'.$value.'" maxlength="'.$max.'" size="'.$size.'" class="'.$CSS.'"';
		if ($type == 'button' || $type == 'submit') {
		$prtSTR .=  ' onclick="this.value=\'Aguarde...\';this.disable=true;"';
		}
		if ($type == 'radio' && $value == $max) {
		$prtSTR .=  ' checked';
		}
	$prtSTR .=  ' />';
	} elseif ($MODE == 'RD') {
		$value = max_caps($value);
	$prtSTR .=  '<label>';
		if ($CSSBold == 'True') {
			$prtSTR .=  '<b>'.$value.'</b>';
		} else { $prtSTR .=  $value; }
		$prtSTR .=  '</label>';
		}
	}
 // TEXTAREA
  if ($type == 'textarea') {
	if ($MODE == 'ED') {
	$prtSTR .=  '<textarea name="'.$name.'" id="'.$name.'" cols="'.$max.'" rows="'.$size.'" class="'.$CSS.'">'.$value.'</textarea>';
	} elseif ($MODE == 'RD') {
		$value = max_caps($value);
	$prtSTR .=  '<label>';
		if ($CSSBold == 'True') {
			$prtSTR .=  '<b>'.$value.'</b>';
		} else { $prtSTR .=  $value; }
		$prtSTR .=  '</label>';
		}
	}
	// SELECT
  if ($type == 'select') {
	if ($MODE == 'ED') {
	$prtSTR .= '<select name="'.$name.'" id="'.$name.'" class="'.$CSS.'">';
	if ($size != '') {
	$prtSTR .= '<option value="">'.$size.'</option>';
	}
	$ListField = $GLOBALS['MYT']->db_array($max);
	$CGET = $ListField[0];
		for ($l = 1; $l <= $CGET; $l++) {
		$prtSTR .= '<option value="'.$ListField[$l]['ID'].'"';
		if ($value == $ListField[$l]['ID']) { $prtSTR .= ' selected'; }
		$prtSTR .= '>'.$ListField[$l]['NAME'].'</option>';
		}
	$prtSTR .= '</select>';
	} elseif ($MODE == 'RD') {
		$size = max_caps($size);
	$prtSTR .=  '<label>';
		if ($CSSBold == 'True') {
			$prtSTR .=  '<b>'.$size.'</b>';
		} else { $prtSTR .=  $size; }
		$prtSTR .=  '</label>';
		}
	}
	// MATRIXSELECT
  if ($type == 'xselect') {
	if ($MODE == 'ED') {
	$prtSTR .=  '<select name="'.$name.'" id="'.$name.'" class="'.$CSS.'">';
	$ListField = $GLOBALS['MYT']->db_array($max);
	$CGET = $ListField[0];
		for ($l = 1; $l <= $CGET; $l++) {
		$prtSTR .=  '<option value="'.$size.';'.$ListField[$l]['ID'].'"';
		if ($value == $ListField[$l]['ID']) { $prtSTR .=  ' selected'; }
		$prtSTR .=  '>'.$ListField[$l]['NAME'].'</option>';
		}
	$prtSTR .=  '</select>';
	} elseif ($MODE == 'RD') {
		$size = max_caps($size);
	$prtSTR .=  '<label>';
		if ($CSSBold == 'True') {
			$prtSTR .=  '<b>'.$size.'</b>';
		} else { $prtSTR .=  $size; }
		$prtSTR .=  '</label>';
		}
	}
	// DBMULTIPLESELECT
  if ($type == 'dselect') {
	if ($MODE == 'ED') {
	$prtSTR .=  '<select name="'.$name.'" id="'.$name.'" size="'.$size.'" multiple class="'.$CSS.'">';
	$ListField = $GLOBALS['MYT']->db_array($max);
		for ($l = 1; $l <= $ListField[0]; $l++) {
		$prtSTR .=  '<option value="'.$ListField[$l]['ID'].'"';
		if (in_array($ListField[$l]['ID'],$value) || (!isset($value[0]) && $l == 1)) { $prtSTR .=  ' selected'; }
		$prtSTR .=  '>'.$ListField[$l]['NAME'].'</option>';
		}
	$prtSTR .=  '</select>';
	} elseif ($MODE == 'RD') {
		$size = max_caps($size);
	$prtSTR .=  '<label>';
		if ($CSSBold == 'True') {
			$prtSTR .=  '<b>'.$size.'</b>';
		} else { $prtSTR .=  $size; }
		$prtSTR .=  '</label>';

		}
	}
	// MULTIPLESELECT
  if ($type == 'mselect') {
	if ($MODE == 'ED') {
	$prtSTR .=  '<select name="'.$name.'" id="'.$name.'" size="'.$size.'" multiple class="'.$CSS.'">';
	$Fields = preg_split("/#/",$max);
	$ListValue = preg_split("/;/",$Fields[1]);
	$ListFields = preg_split("/;/",$Fields[0]);
	$CountFields = count($ListFields);
		for ($l = 0; $l < $CountFields; $l++) {
		$prtSTR .=  '<option value="'.$ListValue[$l].'"';
		if ($value == $ListValue[$l]) { $prtSTR .=  ' selected'; }
		$prtSTR .=  '>'.$ListFields[$l].'</option>';
		}
	$prtSTR .=  '</select>';
	} elseif ($MODE == 'RD') {
		$size = max_caps($size);
	$prtSTR .=  '<label>';
		if ($CSSBold == 'True') {
			$prtSTR .=  '<b>'.$size.'</b>';
		} else { $prtSTR .=  $size; }
		$prtSTR .=  '</label>';

		}
	}
	// MANUALSELECT
  if ($type == 'hselect') {
	if ($MODE == 'ED') {
	$prtSTR .=  '<select name="'.$name.'" id="'.$name.'" class="'.$CSS.'">';
	$Fields = preg_split("/#/",$max);
	$ListValue = preg_split("/;/",$Fields[1]);
	$ListFields = preg_split("/;/",$Fields[0]);
	$CountFields = count($ListFields);
		for ($l = 0; $l < $CountFields; $l++) {
		$prtSTR .=  '<option value="'.$ListValue[$l].'"';
		if ($value == $ListValue[$l]) { $prtSTR .=  ' selected'; }
		$prtSTR .=  '>'.$ListFields[$l].'</option>';
		}
	$prtSTR .=  '</select>';
	} elseif ($MODE == 'RD') {
		$size = max_caps($size);
	$prtSTR .=  '<label>';
		if ($CSSBold == 'True') {
			$prtSTR .=  '<b>'.$size.'</b>';
		} else { $prtSTR .=  $size; }
		$prtSTR .=  '</label>';
		}
	}
 // CHECKBOX
  if ($type == 'checkbox') {
	if ($MODE == 'ED') {
	$prtSTR .=  '<input type="checkbox"
				name="'.$name.'"
				id="'.$name.'"
				value="'.$value.'"
				 '.$max.'
				class="'.$CSS.'" />';
	} elseif ($MODE == 'RD') {
		$value = max_caps($value);
	$prtSTR .=  '<label>';
		if ($CSSBold == 'True') {
			$prtSTR .=  '<b>'.$value.'</b>';
		} else { $prtSTR .=  $value; }
		$prtSTR .=  '</label>';
		}
	}
 // DATECHECK
  if ($type == 'date') {
	if ($MODE == 'ED') {
	if ($value == '') { $value = date("Y-m-d"); }
	$prtSTR .=  '<input type="text" name="'.$name.'" id="'.$name.'" value="'.$value.'"
	maxlength="19" size="'.$size.'" class="'.$CSS.'" ';
	//onkeyup="dtval(this,event);"
	$prtSTR .=  ' /><input type="button" value=""
	onclick="displayCalendar(document.'.$max.'.'.$name.',\'yyyy-mm-dd\',this)" class="calendar" />';
	} elseif ($MODE == 'RD') {
	$prtSTR .=  '<label>';
		if ($CSSBold == 'True') {
			$prtSTR .=  '<b>'.$value.'</b>';
		} else { $prtSTR .=  $value; }
		$prtSTR .=  '</label>';
		}
	}
 // TIMECHECK
  if ($type == 'time') {
	if ($MODE == 'ED') {
	$prtSTR .=  '<input type="'.$type.'" name="'.$name.'" id="'.$name.'" value="'.$value.'" maxlength="'.$max.'" size="'.$size.'" class="'.$CSS.'" />';
	} elseif ($MODE == 'RD') {
	$prtSTR .=  '<label>';
		if ($CSSBold == 'True') {
			$prtSTR .=  '<b>'.$value.'</b>';
		} else { $prtSTR .=  $value; }
		$prtSTR .=  '</label>';
		}
	}
	return $prtSTR;
 }
/*
 function mn_field($type,$MODE,$name,$value,$max,$size,$CSSBold,$CSS) {
  $prtSTR = '';
 // INPUT
 	$fieldTypes = array('hidden','text','password','button','submit','file','radio');
  if (in_array($type, $fieldTypes)) {
	if ($MODE == 'ED') {
	echo '<input type="'.$type.'" name="'.$name.'" id="'.$name.'" value="'.$value.'" maxlength="'.$max.'" size="'.$size.'" class="'.$CSS.'"';
		if ($type == 'button' || $type == 'submit') {
		echo ' onclick="this.value=\'Aguarde...\';this.disable=true;"';
		}
		if ($type == 'radio' && $value == $max) {
		echo ' checked';
		}
	echo ' />';
	} elseif ($MODE == 'RD') {
		$value = max_caps($value);
	echo '<label>';
		if ($CSSBold == 'True') {
			echo '<b>'.$value.'</b>';
		} else { echo $value; }
		echo '</label>';
		}
	}
 // TEXTAREA
  if ($type == 'textarea') {
	if ($MODE == 'ED') {
	echo '<textarea name="'.$name.'" id="'.$name.'" cols="'.$max.'" rows="'.$size.'" class="'.$CSS.'">'.$value.'</textarea>';
	} elseif ($MODE == 'RD') {
		$value = max_caps($value);
	echo '<label>';
		if ($CSSBold == 'True') {
			echo '<b>'.$value.'</b>';
		} else { echo $value; }
		echo '</label>';
		}
	}
	// SELECT
  if ($type == 'select') {
	if ($MODE == 'ED') {
	$prtSTR .= '<select name="'.$name.'" id="'.$name.'" class="'.$CSS.'">';
	if ($size != '') {
	$prtSTR .= '<option value="">'.$size.'</option>';
	}
	$ListField = $GLOBALS['MYT']->db_array($max);
	$CGET = $ListField[0];
		for ($l = 1; $l <= $CGET; $l++) {
		$prtSTR .= '<option value="'.$ListField[$l]['ID'].'"';
		if ($value == $ListField[$l]['ID']) { $prtSTR .= ' selected'; }
		$prtSTR .= '>'.$ListField[$l]['NAME'].'</option>';
		}
	$prtSTR .= '</select>';
	} elseif ($MODE == 'RD') {
		$size = max_caps($size);
	echo '<label>';
		if ($CSSBold == 'True') {
			echo '<b>'.$size.'</b>';
		} else { echo $size; }
		echo '</label>';
		}
	}
	// MATRIXSELECT
  if ($type == 'xselect') {
	if ($MODE == 'ED') {
	echo '<select name="'.$name.'" id="'.$name.'" class="'.$CSS.'">';
	$ListField = $GLOBALS['MYT']->db_array($max);
	$CGET = $ListField[0];
		for ($l = 1; $l <= $CGET; $l++) {
		echo '<option value="'.$size.';'.$ListField[$l]['ID'].'"';
		if ($value == $ListField[$l]['ID']) { echo ' selected'; }
		echo '>'.$ListField[$l]['NAME'].'</option>';
		}
	echo '</select>';
	} elseif ($MODE == 'RD') {
		$size = max_caps($size);
	echo '<label>';
		if ($CSSBold == 'True') {
			echo '<b>'.$size.'</b>';
		} else { echo $size; }
		echo '</label>';
		}
	}
	// DBMULTIPLESELECT
  if ($type == 'dselect') {
	if ($MODE == 'ED') {
	echo '<select name="'.$name.'" id="'.$name.'" size="'.$size.'" multiple class="'.$CSS.'">';
	$ListField = $GLOBALS['MYT']->db_array($max);
		for ($l = 1; $l <= $ListField[0]; $l++) {
		echo '<option value="'.$ListField[$l]['ID'].'"';
		if (in_array($ListField[$l]['ID'],$value) || (!isset($value[0]) && $l == 1)) { echo ' selected'; }
		echo '>'.$ListField[$l]['NAME'].'</option>';
		}
	echo '</select>';
	} elseif ($MODE == 'RD') {
		$size = max_caps($size);
	echo '<label>';
		if ($CSSBold == 'True') {
			echo '<b>'.$size.'</b>';
		} else { echo $size; }
		echo '</label>';

		}
	}
	// MULTIPLESELECT
  if ($type == 'mselect') {
	if ($MODE == 'ED') {
	echo '<select name="'.$name.'" id="'.$name.'" size="'.$size.'" multiple class="'.$CSS.'">';
	$Fields = split("#",$max);
	$ListValue = split(";",$Fields[1]);
	$ListFields = split(";",$Fields[0]);
	$CountFields = count($ListFields);
		for ($l = 0; $l < $CountFields; $l++) {
		echo '<option value="'.$ListValue[$l].'"';
		if ($value == $ListValue[$l]) { echo ' selected'; }
		echo '>'.$ListFields[$l].'</option>';
		}
	echo '</select>';
	} elseif ($MODE == 'RD') {
		$size = max_caps($size);
	echo '<label>';
		if ($CSSBold == 'True') {
			echo '<b>'.$size.'</b>';
		} else { echo $size; }
		echo '</label>';

		}
	}
	// MANUALSELECT
  if ($type == 'hselect') {
	if ($MODE == 'ED') {
	echo '<select name="'.$name.'" id="'.$name.'" class="'.$CSS.'">';
	$Fields = split("#",$max);
	$ListValue = split(";",$Fields[1]);
	$ListFields = split(";",$Fields[0]);
	$CountFields = count($ListFields);
		for ($l = 0; $l < $CountFields; $l++) {
		echo '<option value="'.$ListValue[$l].'"';
		if ($value == $ListValue[$l]) { echo ' selected'; }
		echo '>'.$ListFields[$l].'</option>';
		}
	echo '</select>';
	} elseif ($MODE == 'RD') {
		$size = max_caps($size);
	echo '<label>';
		if ($CSSBold == 'True') {
			echo '<b>'.$size.'</b>';
		} else { echo $size; }
		echo '</label>';
		}
	}
 // CHECKBOX
  if ($type == 'checkbox') {
	if ($MODE == 'ED') {
	echo '<input type="checkbox"
				name="'.$name.'"
				id="'.$name.'"
				value="'.$value.'"
				 '.$max.'
				class="'.$CSS.'" />';
	} elseif ($MODE == 'RD') {
		$value = max_caps($value);
	echo '<label>';
		if ($CSSBold == 'True') {
			echo '<b>'.$value.'</b>';
		} else { echo $value; }
		echo '</label>';
		}
	}
 // DATECHECK
  if ($type == 'date') {
	if ($MODE == 'ED') {
	if ($value == '') { $value = date("Y-m-d"); }
	echo '<input type="text" name="'.$name.'" id="'.$name.'" value="'.$value.'"
	maxlength="19" size="'.$size.'" class="'.$CSS.'" ';
	//onkeyup="dtval(this,event);"
	echo ' /><input type="button" value=""
	onclick="displayCalendar(document.'.$max.'.'.$name.',\'yyyy-mm-dd\',this)" class="calendar" />';
	} elseif ($MODE == 'RD') {
	echo '<label>';
		if ($CSSBold == 'True') {
			echo '<b>'.$value.'</b>';
		} else { echo $value; }
		echo '</label>';
		}
	}
 // TIMECHECK
  if ($type == 'time') {
	if ($MODE == 'ED') {
	echo '<input type="'.$type.'" name="'.$name.'" id="'.$name.'" value="'.$value.'" maxlength="'.$max.'" size="'.$size.'" class="'.$CSS.'" />';
	} elseif ($MODE == 'RD') {
	echo '<label>';
		if ($CSSBold == 'True') {
			echo '<b>'.$value.'</b>';
		} else { echo $value; }
		echo '</label>';
		}
	}
	echo $prtSTR;
 } */
function mn_field($type,$MODE,$name,$value,$max,$size,$CSSBold,$CSS) {
	echo rt_field($type,$MODE,$name,$value,$max,$size,$CSSBold,$CSS);
 }
 ?>